﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Com.CMS263.PO;

namespace Com.CMS263.DAO
{
    public class AdminRoleDAO
    {
        public void Add(AdminRole adminUser)
        {
            DBHelper.TransSaveOrUpdate(adminUser);
        }
        public void DeleteUserById(int id)
        {
            DBHelper.TransDeleteByID(" AdminRole ", id);
        }
        public void ModifyAdminUser(AdminRole adminUser)
        {
            DBHelper.TransSaveOrUpdate(adminUser);
        }
        public IList<AdminRole> GetAllAdminRole()
        {
            return DBHelper.ExecuteHQL("from AdminRole ").List<AdminRole>();
        }

        public bool isExist(string roleName)
        {
            return DBHelper.ExecuteHQL("from AdminRole where roleName='" + roleName + "'").List().Count > 0;
        }

        public AdminRole GetAdminUserByID(int id)
        {
            return (AdminRole)DBHelper.GetObject(typeof(AdminRole), id);
        }
        public string GetAdminPowerByID(int id)
        {
            try
            {
                AdminRole ar=  DBHelper.ExecuteHQL("from AdminRole where id = " + id).List<AdminRole>().First();
                return ar.rolePower.Trim();
            }
            catch 
            {

                return "";
            }
        }
    }
}
